package com.conduit.agent;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.sikuli.script.Screen;

public class Main {

	public static void main(String[] args) {
		// int commandIndex = 1;
		Agent agent = new Agent();
		String ipAddress = "";
		try {
			ipAddress = getMachineIp();
		} catch (Exception e) {
			System.out.println("Could not get IP address of local machine");
		}
		try {
			FileInputStream fstream = new FileInputStream(args[0]);
			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;

			// Read File Line By Line
			while ((strLine = br.readLine()) != null) {
				if (strLine.startsWith("//")) {
					continue;

				}
				agent.executeCommand(strLine);
				System.out.println(agent.report(ipAddress));

				// commandIndex++;

			}
			// Close the input stream
			in.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

	public static String getMachineIp() throws Exception {
		InetAddress inetAddress;
		inetAddress = InetAddress.getLocalHost();
		return inetAddress.getHostAddress();
	}

}
